package com.sky.controller.user;

import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@RequestMapping("/user/order")

public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> orderCreat (@RequestBody OrdersSubmitDTO ordersSubmitDTO){
     OrderSubmitVO orderSubmitVO = orderService.orderCreat(ordersSubmitDTO);
     return Result.success(orderSubmitVO);
    }

    /**
     * 历史订单查询
     *
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> HistoricalOrderInquiry (Integer page ,int pageSize,Integer status){

      PageResult pageResult  =orderService.HistoricalOrderInquiry ( page , pageSize,status);
      return Result.success(pageResult);
    }
    /**
     * 查询订单详情
     *
     */
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> selectWithOrderDetail (@PathVariable Long id ){

        OrderVO orderVO = orderService.selectWithOrderDetail (id );
        return Result.success(orderVO);
    }
    /**
     * 取消订单
     */
    @PutMapping("/cancel/{id}")
    public Result cancelOrder (@PathVariable Long id ){

         orderService.cancelOrder (id );
        return Result.success();
    }

    /**
     * 再来一单
     * @param
     * @return
     */
    @PostMapping("/repetition/{id}")
    public Result againOrder (@PathVariable Long id ){
        orderService.againOrder(id);
        return Result.success();
    }
    /**
     * 用户催单
     *
     * @param id
     * @return
     */
    @GetMapping("/reminder/{id}")
    @ApiOperation("用户催单")
    public Result reminder(@PathVariable("id") Long id) {
        orderService.reminder(id);
        return Result.success();
    }

}
